﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UniMana.Utils.CusControls;
using UniMana.Data.Quiz;
using UniMana.Utils.Config;

namespace UniMana.Lib.Quiz
{
    public class Quiz_TestDetailInfo
    {
        public bds m_bds = new bds();
        private DBQuiz m_data = new DBQuiz();


        public Quiz_TestDetailInfo()
        {
            m_bds.DataSource = typeof(Quiz_TestDetail);
        }

        public Quiz_TestDetailInfo(string _strTestKey = DefaultConfig.EMPTY_GUID, string _questionKey="")
        {
            var Iquery = m_data.m_DCSave.Quiz_TestDetails.Where(p => p.Quiz_TestKey == Guid.Parse(_strTestKey)
                                                                  && p.Quiz_QuestionKey == _questionKey);
             m_bds.DataSource = Iquery;
             var Row = Iquery.FirstOrDefault();
             if (Row == null)
             {
                 Row = new Quiz_TestDetail();
                 Row.Quiz_TestKey = Guid.Parse(_strTestKey);
                 Row.Quiz_QuestionKey = _questionKey;
                  m_bds.Add(Row);
                  m_bds.MoveLast();
                
             }
        }


        public Quiz_TestDetail Properties
        {
            get { return m_bds.Current as Quiz_TestDetail; }
        }

        /// <summary>
        /// Xóa đối tượng hiện hành
        /// </summary>
        public void Delete()
        {
            m_bds.DeleteCurrent();
        }

        /// <summary>
        /// Lưu đối tượng hiện hành
        /// </summary>
        public void Save()
        {
            m_bds.EndEdit();
            m_data.m_DCSave.SubmitChanges();
        }
    }
}
